# 1、导包
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.service import Service
from time import sleep

# 2、实例化浏览器对象
driver_path = "C:/Users/Lenovo/AppData/Local/Programs/Python/Python310/geckodriver.exe"
service = Service(executable_path=driver_path)
driver = webdriver.Firefox(service=service)
driver.get("file:///E:/project/learn-python/html%E5%9F%BA%E7%A1%80/3-%E8%A1%A8%E5%8D%95%E6%8F%90%E4%BA%A4.html")

# 3、需求

# ① 返回元素大小
uername = driver.find_element(By.ID, "user").size
# print("元素的尺寸为：", uername.size)

# ② 获取元素的文本
btn = driver.find_element(By.TAG_NAME, "button").text
# print("元素的文本为：", btn.text)

# ③ 获取属性值
link = driver.find_element(By.LINK_TEXT, "新浪").get_attribute("href")
# print("元素的地址为：", link.get_attribute("href"))

# ④ 判断元素是否可见
span = driver.find_element(By.NAME, "sp1").is_displayed()
# print("元素是否显示：", span.is_displayed())

# ⑤ 判断元素是否可用
can_btn= driver.find_element(By.ID, "cancel").is_enabled()
# print("元素是否可用", can_btn.is_enabled())

# ⑥ 判断元素是否选中
check = driver.find_element(By.ID, "yglgzx").is_selected()
# print("元素是否选中:", check.is_selected())

# 扩展：判断条件
'''
if check.is_selected():        # 选中
    pass
if not check.is_selected():    # 未选中
    pass
'''